All Questions
10 questions
1vote
1answer
5kviews
Putting string with newline separated words into array
I currently have a a bash variable that holds a string similar to this one, where each different phrase is separated by a newline: var="1st word 2nd word 4th word" Note there is an empty ...
0votes
1answer
817views
More efficient zsh string parsing / array handling
Is there any more efficient way to do the following in zsh? I imagine that there might be ways to get rid of the intermediate array parameters a and/or b. The script gets some output from a command. ...
2votes
4answers
970views
String Manipulation Shell Script [duplicate]
I am working on a UPS Monitoring project using NUT Server. My objective is to make a shell script which sends one command and in response receives the status and other parameters from the UPS. for ...
18votes
3answers
22kviews
Go from a String to an Array of "words" in Bash
I need to go from a string to an array where each entry is each word on that string. For example, starting with: VotePedro="Vote for Pedro" I need the array: Vote For Pedro Which I should then be ...
15votes
4answers
18kviews
How can I prepend and append to each member of an array?
I have an array: CATEGORIES=(one two three four) I can prepend to each array member using parameter expansion: echo ${CATEGORIES[@]/#/foo } I can append to each array member the same way: echo ${...
7votes
2answers
8kviews
Splitting the working directory in a bash script
If I do: IFS="/" read -ra PARTS And type in a path manually, it creates the array "PARTS" as hoped, however: IFS="/" read -ra PARTS <<< $(pwd) creates an array with a single element, with ...
5votes
4answers
10kviews
Bash : Native way to get rid of quotation around each array member
I read an array from another script. This array needs to put " " around all array members since some members are empty. in_file=./data vector=($(./readdata.sh 0 $in_file)) for index in ${!vector[@]} ...
1vote
2answers
3kviews
Read file remove spaces and store in array
I have a file with the following content: list: blue,none red,none orange,plot baseball , none university,none school,none desk,plot monitor,none earphone,none I need to read this file, ...
2votes
1answer
1kviews
Generate array of strings combined with number
I would like to generate a local array in a shell/bash script that consists of the following elements: JF-1998, JF-1999, JF-2000,... , JF-2011. That is, a string JF- combined with the years from 1998 ...
1vote
1answer
1kviews
Zsh script how to concatanate array elements with string
I have written a zsh script to automize an analysis in high energy physics and now I would like to use an element of the one of the defined array some string and another element of some another array ...